<!--
 * @Author: wuyuanhong wuyuanhong@szhbzc.com
 * @Date: 2024-04-08 17:48:59
 * @LastEditors: wuyuanhong wuyuanhong@szhbzc.com
 * @LastEditTime: 2024-07-10 12:04:58
 * @FilePath: \xiamenAgency\src\components\main\components\user\user.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div class="user-avatar-dropdown">
    <Dropdown @on-click="handleClick" trigger="click">
      <div style="
          position: relative;
          padding-right: 50px;
          display: flex;
          align-items: center;
        ">
        <span style="margin-right: 10px; color: #2d8cf0; font-size: 14px">{{
          vuex_user.base.name
        }}</span>
        <cusCircle></cusCircle>
      </div>

      <DropdownMenu slot="list">
        <DropdownItem name="operationManual">{{systemCode == 'business'?'业务':'机关'}}系统操作手册</DropdownItem>
        <DropdownItem name="accounting" v-if="systemCode == 'business'">核算模块操作手册</DropdownItem>
        <DropdownItem name="message">
          个人中心
          <Badge style="margin-left: 10px" :count="messageUnreadCount"></Badge>
        </DropdownItem>
        <DropdownItem name="logout">退出登录</DropdownItem>
      </DropdownMenu>
    </Dropdown>
  </div>
</template>

<script>
import cusCircle from "./components/cus-circle";
import "./user.less";
import { loginOut } from "@/api/organ/system";

export default {
  components: { cusCircle },
  name: "User",
  props: {
    userAvatar: {
      type: String,
      default: "",
    },
    messageUnreadCount: {
      type: Number,
      default: 0,
    },
  },
  data() {
    return {
      systemCode:localStorage.getItem('systemCode'),
    };
  },
  methods: {
    logout(event) {
      this.$cu
        .dialog({
          content: "确认退出当前账号?",
        })
        .then(() => {
          this.$cu.showLoading({ content: "角色退出中.." });
          loginOut({}).then((res) => {
            if (res.code === 1) {
              this.$cu.hideLoading();
              this.$Message.success("退出成功");
              this.$store.commit("$uStore", {
                name: "vuex_user",
                value: "",
              });
              localStorage.clear();
              this.$router.push("/login");

              this.$cu.eventBus.$emit("onLogout");
            } else this.$cu.hideLoading(1.5);
          });
        });
    },
    message() {
      this.$router.push("/personal/index");
    },
    operationManual(isHesuan) {
      console.log('操作手册');
      // let systemCode = localStorage.getItem('systemCode');
      let httpAddress = `http://${window.location.hostname}:12570`
      if (isHesuan) {
        window.open(
          `${Object.is(process.env.NODE_ENV, 'production')
            ? httpAddress
            : 'http://172.16.1.27:12570'
          }/statics/data/智慧食堂核算系统操作手册.pdf`
        );
        return;
      }
      window.open(
        `${Object.is(process.env.NODE_ENV, 'production')
          ? httpAddress
          : 'http://172.16.1.27:12570'
        }/statics/data/${this.systemCode == 'business' ? '智厨业务系统' : '伙食保障精细管理系统'}操作手册.pdf`
      );
    },
    handleClick(name) {
      switch (name) {
        case "logout":
          this.logout();
          break;
        case "message":
          this.message();
          break;
        case "operationManual":
          this.operationManual(false);
          break;
        case "accounting":
          this.operationManual(true);
          break;
      }
    },
  },
};
</script>
